package cn.wolfcode.consumer.api._04_consumer_way;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.beans.IntrospectionException;
import java.util.List;

public class consumer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //1.创建一个拉取消息的消费者对象
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("wolfcode-consumer");
        //2.设置名字地址
        consumer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动消费者
        consumer.start();
        //4.主动拉取消息
        PullResult pullResult = consumer.pull(new MessageQueue("04-consumer-way", "broker-a", 0), "*", 0, 10);
        List<MessageExt> list = pullResult.getMsgFoundList();
        for (MessageExt messageExt : list) {
            System.out.println("消息的内容是"+new String(messageExt.getBody()));
        }

    }

}
